'use strict';
define(function(require, exports, module) {

	exports.init = function(app) {

		app.config(['$controllerProvider', '$compileProvider', '$filterProvider', '$provide', '$stateProvider', '$urlRouterProvider', function($controllerProvider, $compileProvider, $filterProvider, $provide, $stateProvider, $urlRouterProvider) {

			app.register = {
				controller: $controllerProvider.register,
				directive: $compileProvider.directive,
				filter: $filterProvider.register,
				factory: $provide.factory,
				service: $provide.service,
				registerState: $stateProvider.state,
				urlRouterProvider: $urlRouterProvider
			};

			//注册路由controller.js文件的加载方法
			app.getRouteResolve = function(src) {
				return {
					load: function($$q, $rootScope) {
						var deferred = $$q.defer();
						var dependencies = src;

						require.async(dependencies, function(mod) {

							console.info("lazy load route controller.");

							mod.init(app);

							if (!$rootScope.$$phase) {
								$rootScope.$apply(function() {
									deferred.resolve();
								});
							}

						});
						return deferred.promise;
					}
				};
			};

		}]);

	};

});